package com.zhaoxi.project.wms.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.wms.domain.WmsProductStockLog;
import com.zhaoxi.project.wms.service.impl.WmsProductStockLogServiceImpl;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 出入库记录Controller
 *
 * @author zhaoxi
 * @date 2023-08-25
 */
@RestController
@RequestMapping("/wms/stockLog")
public class WmsProductStockLogController extends BaseService {
    @Autowired
    private WmsProductStockLogServiceImpl wmsProductStockLogService;

    /**
     * 查询出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stockLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsProductStockLog wmsProductStockLog) {
        startPage();
        List<WmsProductStockLog> list = wmsProductStockLogService.selectWmsProductStockLogList(wmsProductStockLog);
        return getDataTable(list);
    }

    /**
     * 导出出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stockLog:export')")
    @Log(title = "出入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsProductStockLog wmsProductStockLog) {
        List<WmsProductStockLog> list = wmsProductStockLogService.selectWmsProductStockLogList(wmsProductStockLog);
        ExcelUtil<WmsProductStockLog> util = new ExcelUtil<WmsProductStockLog>(WmsProductStockLog.class);
        util.exportExcel(response, list, "出入库记录数据");
    }

    /**
     * 获取出入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:stockLog:query')")
    @GetMapping(value = "/{id}")
    public PageData getInfo(@PathVariable("id") Long id) {
        return success(wmsProductStockLogService.selectWmsProductStockLogById(id));
    }

    /**
     * 新增出入库记录
     */
    @PreAuthorize("@ss.hasPermi('wms:stockLog:add')")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public PageData add(@RequestBody WmsProductStockLog wmsProductStockLog) {
        return toAjax(wmsProductStockLogService.insertWmsProductStockLog(wmsProductStockLog));
    }
}
